<template>
<!--  大div-->
  <div id="myApp">
<!--    头部div-->
    <div id="topDiv">
      <span style="margin-left: 6%;">{{topName}}</span>
      <el-button type="primary" @click="handleClick" style="position: relative;left: 550px;">退出登录</el-button>
    </div>
<!--    身体部分的div-->
    <div id="middleDiv">
<!--      身体部分左边的div-->
      <div id="leftDiv">
        <!--        将左边的导航栏改成动态的-->
        <el-row class="tac" style="margin-left: 1px">
          <el-col :span="24">
            <el-menu
                default-active="2"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose">
              <el-submenu :index="item.menuId" v-for="item in mainMenuList":key="item.menuId">
                <template slot="title">
                  <i class="el-icon-location"></i>
                  <span>{{item.menuName}}</span>
                </template>

                <el-menu-item-group>
                  <el-menu-item @click="$router.push(child.menuUrl)" v-for="child in  item.subMenuList" :key="child.menuId" >{{child.menuName}}</el-menu-item>
                </el-menu-item-group>
              </el-submenu>

            </el-menu>
          </el-col>
        </el-row>
      </div>

<!--     身体部分右边的div-->
      <div id="rightDiv">
        <!--          放你要显示的东西-->
        <router-view></router-view>
      </div>
    </div>
<!--    底部的div-->
    <div id="footDiv"></div>
  </div>
</template>

<script>
export default {
  name: "index",
  data(){
    return{
      topName:"摩托管理系统",
      mainMenuList:[],
      userName:'',
    }
  },
  created() {
    //从路由传过来登陆用户名
    this.userName= this.$route.params.userName
    this.getMenuList();
  },
  methods:{
    //加载导航栏
    getMenuList(){
      this.$request({
        method:'get',
        url: '/loadMenu',
        // headers:{
        //   token: sessionStorage.setItem("token")
        // },
        params:{
          userName:this.userName
          /*,
          token: sessionStorage.getItem("token")*/
        }

      },res=>{
        //得到传送过来的数据，赋值给bookList
        this.mainMenuList= res.data;
      },error=>{
        console.log("失败，数据是："+ error.data);
      },8100)
    },
    handleClick() {
      this.$router.push("/login"); // 调用 $router.push() 方法跳转到指定页面
    },
    //导航栏点击打开和关闭的事件
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },

    //退出按钮的事件
    logout () {
      // 清空token
      window.sessionStorage.clear();
      // 重新回到登录页面
      this.$router.push('/')
    }
  }

}
</script>

<style scoped>
#myApp{
  width: 100%;
  height: 600px;
}
#topDiv{
  width: 100%;
  height: 70px;
  background-color: #C0C0C0;
  color: white;
  font-family: "Agency FB";
  font-weight: bold;
  font-size: 30px;
}

#topDiv span{
  line-height: 70px;
}
#middleDiv{
  width: 100%;
  height: 530px;
}
#leftDiv{
  width: 20%;
  height: 530px;
  float: left;
  background-color: #C0C0C0;
}

#ulDiv{
  border: solid 1px snow ;
  background-color: #f5f5f5;
}
#ulDiv ul li{
  margin-left: -40px;
  list-style: none;
  text-decoration: none;
}
li a:hover{
  background-color: gold;
  display: block;
  color: black;
}
#rightDiv{
  width: 70%;
  height: 530px;
  float: left;
  background-color: #ffffff;
}
#footDiv{
  width: 100%;
  height: 70px;
  background-color: #C0C0C0;
}
</style>